package br.edu.ufcg.dsc.actions.resource;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public abstract class ResourceDriven<T> extends ActionSupport implements ModelDriven<T> {
	
	protected T model;
	
	@SuppressWarnings("unchecked")
	public T getModel() {
		if (ActionContext.getContext().getSession().containsKey("changeToSimpleResource")) {
			model = (T)  ActionContext.getContext().getSession().get("changeToSimpleResource");
			ActionContext.getContext().getSession().remove("changeToSimpleResource");
			return model; 
		}
		else
			return model = createModel();
	}

	protected abstract T createModel();
	
}
